package club.hicode.daydayup.guava;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.io.Files;
import com.google.common.io.MoreFiles;
import org.junit.Test;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * XXXX
 *
 * @author LiuChunfu
 * @date 2018/6/11
 */
public class GuavaTest1 {

    @Test
    public void test1() {
        String path = "E:\\8. 其他学习\\汪文君Google Guava实战视频";
        File[] ls = FileUtil.ls(path);
        List<File> wmv = Arrays.stream(ls).filter(file -> file.getAbsolutePath().endsWith("wmv")).collect(Collectors.toList());
        wmv.forEach(f -> f.renameTo(new File(StrUtil.replace(f.getName(), "wmv", "avi"))));
    }

    @Test
    public void test2() {
        File oriFile = new File("/Volumes/MyWork/!GitProject/ConerstoneMulti/util");
        //Iterable<File> files = Files.fileTraverser().depthFirstPreOrder(oriFile);
        //for (File file : files) {
        //    System.out.println(file.getAbsolutePath());
        //}

        Iterable<File> files1 = Files.fileTraverser().breadthFirst(oriFile);
        for (File file : files1) {
            System.out.println(file.getAbsolutePath());
        }

        //MoreFiles.fileTraverser().breadthFirst(oriFile);
    }
}
